package com.jic.product.impl;

import java.lang.Long;
import java.util.List;

import com.jic.product.common.util.BeanUtil;
import com.jic.product.entity.CategoryTreeNodeProduct;
import com.jic.product.manage.request.CategoryTreeNodeAddProductRequest;
import com.jic.product.manage.request.CategoryTreeNodeProductRequest;
import com.jic.product.manage.response.CategoryTreeNodeProductResponse;
import com.jic.product.mapper.CategoryTreeNodeProductMapper;
import com.jic.product.service.CategoryTreeNodeProductService;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类目聚合商品表
 * @author : 
 * @email : 
 * @since : 2020-01-10 07:03:01
 * @version : v1.0.0
 */
@Service
public class CategoryTreeNodeProductServiceImpl implements CategoryTreeNodeProductService{

    @Autowired
    private CategoryTreeNodeProductMapper categoryTreeNodeProductMapper;

    @Override
    public long insert(CategoryTreeNodeAddProductRequest categoryTreeNodeAddProductRequest) {
        long flag=0;
        for(CategoryTreeNodeProductRequest categoryTreeNodeProductRequest1:categoryTreeNodeAddProductRequest.getCategoryTreeNodeProductRequests()){
            CategoryTreeNodeProduct categoryTreeNodeProduct=BeanUtil.copy(categoryTreeNodeProductRequest1,CategoryTreeNodeProduct.class);
            flag=categoryTreeNodeProductMapper.insert(categoryTreeNodeProduct);
        }
        return flag;
    }

    @Override
    public long delete(Long id) {
        return categoryTreeNodeProductMapper.delete(id);
    }

    @Override
    public CategoryTreeNodeProduct queryByPrimaryKey(Long id){
        return categoryTreeNodeProductMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CategoryTreeNodeProduct> query(CategoryTreeNodeProduct categoryTreeNodeProduct){
        return categoryTreeNodeProductMapper.query(categoryTreeNodeProduct);
    }

    @Override
    public PageResult<CategoryTreeNodeProductResponse> queryPage(CategoryTreeNodeProductRequest categoryTreeNodeProductRequest, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CategoryTreeNodeProductResponse> list = categoryTreeNodeProductMapper.queryPage(startIndex, pageQuery.getLimit(), categoryTreeNodeProductRequest);
        long count = categoryTreeNodeProductMapper.queryPageCount(categoryTreeNodeProductRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}